<?php
/**
 * Created by PhpStorm.
 * User: alice
 * Date: 2015/12/28
 * Time: 12:26
 */

/**
 * Class Involved_CircleModel
 */

class Involved_CircleModel extends BaseModel{

    protected $table = 'circle';


    /**
     * 获取圈子列表
     * @return mixed
     */
    public function GetOrderList($user_id)
    {
        return  DB::table($this->table)->where('user_id',$user_id)->get();
    }

    /**
     * 获取圈子动态
     * @return mixed
     * @author alice
     * @date 2016-1-27
     */
    public function getCircles($user_id, $page,$is_self)
    {
        #分页
        $offset = ($page-1) * HostEnum::PAGE_NUM;

        if($is_self == 0)
        {
            return DB::table($this->table)
                ->select('circle.circle_id', 'circle.content', 'circle.created', 'circle.show_img1', 'circle.show_img2', 'circle.show_img3', 'circle.show_img4', 'circle.show_img5', 'circle.show_img6', 'circle.show_img7', 'circle.show_img8', 'circle.show_img9',
                    'user.user_name', 'user.avatar', 'user.user_id')
                ->leftJoin('user', 'user.user_id', '=', 'circle.supplier_id')
                ->orderBy('circle.circle_id','desc')
                ->skip($offset)->take(HostEnum::PAGE_NUM)
                ->get();
        }else{
            return DB::table($this->table)
                ->select('circle.circle_id', 'circle.content', 'circle.created', 'circle.show_img1', 'circle.show_img2', 'circle.show_img3', 'circle.show_img4', 'circle.show_img5', 'circle.show_img6', 'circle.show_img7', 'circle.show_img8', 'circle.show_img9',
                    'user.user_name', 'user.avatar', 'user.user_id')
                ->leftJoin('user', 'user.user_id', '=', 'circle.supplier_id')
                ->where('circle.supplier_id',$user_id)
                ->orderBy('circle.circle_id','desc')
                ->skip($offset)->take(HostEnum::PAGE_NUM)
                ->get();
        }



    }

    public function GetCircleSupplierById($circle_id)
    {
        return DB::table($this->table)
                ->select('supplier_id')
                ->where('circle_id',$circle_id)
                ->first();
    }














}